﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.IO;
using System.Windows.Controls;
using HalconDotNet;
using Project1.Model;
using CommonLib;
using ElementLib;
using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight.Command;

namespace Project1.View
{
    /// <summary>
    /// CoreView2.xaml 的交互逻辑
    /// </summary>


    public partial class CoreView2 : Window
    {
      
        private ContextMenu cm;
        private List<UserControl> userControlList;
        object image_lock = new object();
        HTuple hv_Width = new HTuple(), hv_Height = new HTuple();
        private HObject ho_Image = new HObject();     //图像变量
        public CoreView2()
        {
            InitializeComponent();
            InitUserControlList();
            Messenger.Default.Register<string>(this,"ReqBack",OnResponse);
        }

        private void InitUserControlList()
        {
            userControlList = new List<UserControl>();
        /*    userControlList.Add(UserControlCircle);
            userControlList.Add(UserControlPoint);
            userControlList.Add(UserControlLine);
            userControlList.Add(UserControlPeakPoint);*/
        }
        private void OnResponse(string msg)
        {
          if(msg == "back")
            {
                Messenger.Default.Send<string>("dispSelectionCard", "CallBack");
            }
        }
        private RelayCommand sendCommand;
        public RelayCommand SendCommand
        {
            get
            {
                if (sendCommand == null)
                    sendCommand = new RelayCommand(() => SendCommand_ShowImage());
                return sendCommand;

            }
            set { sendCommand = value; }
        }
        private void SendCommand_ShowImage()
        {
            Messenger.Default.Send<string>("ViewModel通知View弹出消息框", "ViewAlert"); //注意：token参数一致
        }

        private void hSmartWindowControlWPF1_Loaded(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("已经加载了");
        }

        private void OnClearAllObjects_Click(object sender, RoutedEventArgs e)
        {
            Messenger.Default.Send<string>("clear", "Draw");
        }

        private void Button_Detect_Point(object sender, RoutedEventArgs e)
        {
           
            //tabControl.Visibility = Visibility.Hidden;
            //UserControlPoint.Visibility = Visibility.Visible;
            Messenger.Default.Send<int>(ConstValue.MEASURE_POINT, "MeasureType");
        }

        private void Button_Detect_PeakPoint(object sender, RoutedEventArgs e)
        {
           tabControl.Visibility = Visibility.Hidden;
          //  UserControlPeakPoint.Visibility = Visibility.Visible;
          //  Messenger.Default.Send<int>(Plan.MEASURE_POINT_PEAK, "MeasureType");
        }
        
        public void execute(object sender, RoutedEventArgs e)
        {
            
        }

        private void Button_Back(object sender, RoutedEventArgs e)
        {
            foreach(var userControl in userControlList)
            {
                if(userControl.Visibility == Visibility.Visible)
                {
                    userControl.Visibility = Visibility.Hidden;
                }
            }
            tabControl.Visibility = Visibility.Visible;
        }
        private void Button_Detect_Line(object sender, RoutedEventArgs e)
        {
           tabControl.Visibility = Visibility.Hidden;
         //  UserControlLine.Visibility = Visibility.Visible;
           Messenger.Default.Send<int>(ConstValue.MEASURE_LINE, "MeasureType");
        }
        private void Button_Detect_LMid(object sender, RoutedEventArgs e)
        {


        }
        private void Button_Detect_LL(object sender, RoutedEventArgs e)
        {
           

        }

        private void Button_Detect_LC(object sender, RoutedEventArgs e)
        {


        }

        private void Button_Detect_CC(object sender, RoutedEventArgs e)
        {


        }

        private void Button_Detect_CCenter(object sender, RoutedEventArgs e)
        {


        }

        private void Button_Detect_ArcCenter(object sender, RoutedEventArgs e)
        {


        }
        private void Button_Measure_Angle(object sender, RoutedEventArgs e)
        {


        }
        private void Button_Measure_RArc(object sender, RoutedEventArgs e)
        {


        }
                
        private void Button_Detect_AverLL(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Measure_TruePorosity(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Measure_Concentricity(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Measure_Straightness(object sender, RoutedEventArgs e)
        {
           
        }
        private void Button_Measure_Parallelism(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Measure_StraightAngle(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Measure_Roundness(object sender, RoutedEventArgs e)
        {

        }                     
        private void Button_Detect_AverPL(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Detect_AverPP(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Detect_VerticalL(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Detect_Parallel(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Detect_FitLine(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Detect_LineCombine(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Detect_PCTangent(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Detect_InnerCircle(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Detect_SupCircle(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Detect_InCircle(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Detect_FitCircle(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Detect_CombineCircle(object sender, RoutedEventArgs e)
        {

        }

   
        private void Button_Detect_ArcPeakPoint(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Detect_PeakLine(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Detect_PeakCircle(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Detect_Arc(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Detect_PeakArc(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Measure_PPDist(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Measure_PLDist(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Measure_LLDist(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Measure_PCDist(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Measure_LCDist(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Measure_CCDist(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Measure_CRadius(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Measure_ArcAngle(object sender, RoutedEventArgs e)
        {

        }
                 
        private void Button_Detect_Circle(object sender, RoutedEventArgs e)
        {
           tabControl.Visibility = Visibility.Hidden;
           //UserControlCircle.Visibility = Visibility.Visible;
           Messenger.Default.Send<int>(ConstValue.MEASURE_CIRCLE, "MeasureType");
        }
     
 
        private void OnRectangle1_Click(object sender, RoutedEventArgs e)
        {
            Messenger.Default.Send<string>("rectangle1","Draw");
        }

        private void OnRectangle2_Click(object sender, RoutedEventArgs e)
        {
            Messenger.Default.Send<string>("rectangle2", "Draw");
        }

        private void OnCircle_Click(object sender, RoutedEventArgs e)
        {
            Messenger.Default.Send<string>("circle", "Draw");
        }

        private void OnEllipse_Click(object sender, RoutedEventArgs e)
        {
            Messenger.Default.Send<string>("ellipse", "Draw");
        }

        private void OnLine_Click(object sender, RoutedEventArgs e)
        {
              Messenger.Default.Send<string>("line", "Draw");
        }

        private void hWindowControlWPF1_HInitWindow(object sender, EventArgs e)
        {
            //Utils.hv_ExpDefaultWinHandle = hSmartWindowControlWPF1.HalconWindow;
        }



        private void hSmartWindowControlWPF1_MouseRightButtonDown(object sender, EventArgs e)
        {
            cm = this.FindResource("cmButton") as ContextMenu;
            cm.PlacementTarget = sender as Button;
            cm.IsOpen = true;
        }

    }
}
